﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.Data;
using HAMath;
namespace HA.ModFlow.Controls.Windows.InterOptionTemporary
{
    /// <summary>
    /// winTempInter.xaml 的交互逻辑
    /// </summary>
    public partial class winTempInter : Window
    {
        public winTempInter(InterpolationOption interOption)
        {
            InitializeComponent();        
            this.InterOption = (InterpolationOption)interOption.Clone();
           
            if (this.InterOption.KrigingOption.ModelVariogram == null)
            {
                this.InterOption.KrigingOption.ModelVariogram = new HAMath.ModelVariogram(HAMath.ModelType.Spherical, 33.35, 0.5, 50.0);
            }
            this.DataContext = this.InterOption;         
        }
              
        InterpolationOption _interOption = new InterpolationOption();

        public InterpolationOption InterOption
        {
            get { return _interOption; }
            set { _interOption = value; }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //if (this._interOption.KrigingOption.KrigType == HAMath.KrigingType.Ordinary)
            //{
            //    this.rbtnOrdinary.IsChecked = true;
               
            //}
            //else
            //{
            //    this.rbtnSimple.IsChecked = true;
              
            //}

            //if (this.cboInterMethod.SelectedIndex == 0) return;
                  

        }


        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            //if (this.rbtnOrdinary.IsChecked.Value)
            //{
            //    this._interOption.KrigingOption.KrigType = HAMath.KrigingType.Ordinary;
            //}
            //else
            //{
            //    this._interOption.KrigingOption.KrigType = HAMath.KrigingType.Simple;
            //}
            this.DialogResult = true;
            this.Close();
        }

        private void cboInterMethod_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.cboInterMethod.SelectedIndex == 0)
            {
                this.tabIDW.Visibility = System.Windows.Visibility.Visible;
                this.tabKriging.Visibility = System.Windows.Visibility.Collapsed;
                this.tabIDW.IsSelected = true;
            }
            else
            {
                this.tabIDW.Visibility = System.Windows.Visibility.Collapsed;
                this.tabKriging.Visibility = System.Windows.Visibility.Visible;
                this.tabKriging.IsSelected = true;
            }
        }


        private void btnEditVariog_Click(object sender, RoutedEventArgs e)
        {
            winEditVariog win = new winEditVariog(this .InterOption.Scatter2d, this._interOption.KrigingOption);
            win.Owner = this;
            if (win.ShowDialog().Value)
            {
                this._interOption.KrigingOption = win.KrigOption;
            }
        }
    }

    public class ConvertToInterpolatetype : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            InterpolateType type = (InterpolateType)value;
            int index = 0;
            switch (type)
            {
                case InterpolateType.IDW:
                    index = 0;
                    break;
                case InterpolateType.Kriging:
                    index = 1;
                    break;
            }
            return index;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            InterpolateType type = InterpolateType.IDW;
            int index = (int )value;
            switch (index)
            {
                case 0:
                    type = InterpolateType.IDW;
                    break;
                case 1:
                    type = InterpolateType.Kriging;
                    break;
            }
            return type;
        }
    }
}
